/**
 * futures : masterlink.futures.filter.AccessTimeFilter.java
 */
package masterlink.futures.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.springframework.http.HttpRequest;

import baytony.util.StringUtil;
import baytony.util.Util;
import baytony.util.log.Log;

import masterlink.futures.controller.LoginController;
import masterlink.futures.util.Constant;
import masterlink.futures.util.WebUtils;
import masterlink.futures.vo.Employee;

/**
 * TODO Write the description
 *
 * @author : tonyyang
 * Create date : 2011/10/28
 * @version 1.0.0	
 */
public class AccessTimeFilter implements Filter {
	
	private static final Logger log=Log.getLogger(AccessTimeFilter.class);
	private FilterConfig config;

	/* (non-Javadoc)
	 * @see javax.servlet.Filter#destroy()
	 */
	@Override
	public void destroy() {
	}

	/* (non-Javadoc)
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request=(HttpServletRequest) req; 
		long start=System.currentTimeMillis();
		String path=request.getServletPath()+StringUtil.trim(request.getPathInfo());
		//log.info("{} \"{}\" started. ",request.getRemoteAddr(),path);
		chain.doFilter(req, res);
		log.info("{} \"{}\" invoke time {} ms.",new Object[]{request.getRemoteAddr(),path,(System.currentTimeMillis()-start)});
	}

	/* (non-Javadoc)
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
	 */
	@Override
	public void init(FilterConfig config) throws ServletException {
		this.config=config;
	}

}
